package com.lib.krismile.ui.main;

import android.os.Handler;
import android.os.Looper;

import androidx.lifecycle.MutableLiveData;

import com.lib.krismile.base.viewmodel.BaseViewModel;
import com.lib.krismile.config.LoadState;
import com.lib.krismile.http.data.HttpDisposable;
import com.lib.krismile.http.request.HttpFactory;
import com.lib.krismile.http.request.HttpRequest;


public class MainViewModel extends BaseViewModel {

    /**
     * 测试mvvm databing使用文本
     */
    private MutableLiveData<String> testMvvmText;

    public MainViewModel() {
        testMvvmText = new MutableLiveData<>();
        loadState.postValue(LoadState.LOADING);
    }


    /**
     * 设置内容你那个
     *   假设网络请求回来获取到的内容
     */
    public void setTestMvvmText() {
        //假设这里做网络请求  成功后的内容
        this.testMvvmText.setValue("我是网络请求回来获取到的内容 ------> 测试文本");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                loadState.postValue(LoadState.SUCCESS);
            }
        },5000);
        HttpRequest.getInstance().getTruckInfo().compose(HttpFactory.schedulers()).safeSubscribe(new HttpDisposable<Object>() {
            @Override
            public void success(Object o) {

            }
        });

    }

    /**
     *
     * @return 获取测试文本内容
     */
    public MutableLiveData<String> getTestMvvmText() {
        return testMvvmText;
    }
}
